<?php
$this->pageTitle = Yii::app()->name . ' - Index';

$this->breadcrumbs = array(
    'Cálculo Vivienda',
);
?>


<?php
$this->widget('bootstrap.widgets.TbAlert', array(
    'alerts' => array('contact'),
));
?>
<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id' => 'calculadora-form',
    //'layout' => TbHtml::FORM_LAYOUTHORIZONTAL,
    'enableClientValidation' => true,
    'clientOptions' => array(
        'validateOnSubmit' => true,
    ),
        ));
?>
<div class="row-fluid page-header">
    <div class="span9"><h2>Generales de la Vivienda</h2></div>
    <div class="span3 text-right"><?php echo TbHtml::submitButton('Guardar', array('color' => TbHtml::BUTTON_COLOR_PRIMARY, 'size' => TbHtml::BUTTON_SIZE_LARGE)),"&nbsp;",TbHtml::resetButton('Restablecer', array('size' => TbHtml::BUTTON_SIZE_LARGE)); ?></div>
</div>
<?php echo $form->errorSummary($model); ?>

<?php echo TbHtml::tabbableTabs(array(
    array('label' => 'General', 'active' => true, 'content' => 
        $form->dropDownListControlGroup($model, 'barrio', CHtml::listData(ValoresUnitariosTerrenosUrbanos::model()->findAll(array('order' => 'barrio')), 'id', 'barrio'), array('size' => TbHtml::INPUT_SIZE_XXLARGE, 'prompt' => Yii::t('App', 'Choose...'))).
        $form->textAreaControlGroup($model, 'direccion', array('size' => 'medium', 'span' => 8, 'rows' => 3, 'placeholder' => 'Escriba la dirección tradicional...')).
        $form->textFieldControlGroup($model, 'dueno', array('size' => TbHtml::INPUT_SIZE_XXLARGE, 'placeholder' => 'Escriba el nombre del propietario...')).
        $form->textFieldControlGroup($model, 'edad', array('size' => TbHtml::INPUT_SIZE_LARGE, 'placeholder' => 'Escriba la edad de la vivienda...','append' => 'años'))
    ),
    array('label' => 'Datos Registrales', 'content' => $form->textFieldControlGroup($model, 'finca',array('size' => TbHtml::INPUT_SIZE_XXLARGE, 'placeholder' => 'Escriba la finca... Ejm. 987654321')).
        $form->textFieldControlGroup($model, 'tomo',array('size' => TbHtml::INPUT_SIZE_XXLARGE, 'placeholder' => 'Escriba el tomo... Ejm. 654321')).
        $form->textFieldControlGroup($model, 'folio',array('size' => TbHtml::INPUT_SIZE_XXLARGE, 'placeholder' => 'Escriba el folio... XXX/XXX/XXX/XXX')). 
        $form->textFieldControlGroup($model, 'asiento',array('size' => TbHtml::INPUT_SIZE_LARGE, 'placeholder' => 'Escriba el asiento... XXX'))), 
    array('label' => 'Inmueble', 'content' => $form->textFieldControlGroup($model, 'numcatastral',array('size' => TbHtml::INPUT_SIZE_XXLARGE, 'placeholder' => 'XXXX-X-XX-XXX-XXXXX')).
        $form->textFieldControlGroup($model, 'areaCatastral',array('size' => TbHtml::INPUT_SIZE_LARGE,'append' => 'm<sup>2</sup>', 'placeholder' => 'XXXX')).
        $form->textFieldControlGroup($model, 'informeValuacion',array('size' => TbHtml::INPUT_SIZE_XXLARGE, 'placeholder' => 'XXXXXX')))),
    array('placement' => TbHtml::TABS_PLACEMENT_RIGHT)
    ); ?>
<div class="row-fluid">
    <div class="span4">
        <fieldset>
            <legend>Construcción</legend>
            <?php echo $form->dropDownListControlGroup($model, 'calidad', array('1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, '10' => 10), array('prompt' => Yii::t('App', 'Choose...'), 'size' => 'medium')); ?>
            <?php echo $form->dropDownListControlGroup($model, 'clase', CHtml::listData(clase::model()->findAll(), 'id', 'nameClase'), array('prompt' => Yii::t('App', 'Choose...'), 'size' => 'large')); ?>
            <?php echo $form->textFieldControlGroup($model, 'areaConstruccion', array('append' => 'm<sup>2</sup>', 'span' => 8)); ?>
            <?php echo $form->dropDownListControlGroup($model, 'factorFormaEstructura', CHtml::listData(FactorFormaEstructura::model()->findAll(), 'id', 'nombreForma'), array('prompt' => Yii::t('App', 'Choose...'))); ?>
            <?php echo $form->dropDownListControlGroup($model, 'factorNivelPlanta', CHtml::listData(FactorNivelPlanta::model()->findAll(), 'id', 'nivelPlanta'), array('prompt' => Yii::t('App', 'Choose...'))); ?>
        </fieldset>
        <fieldset>
            <legend>Porche</legend>
            <?php echo $form->textFieldControlGroup($model, 'areaPorche', array('append' => 'm<sup>2</sup>', 'span' => 8, 'class' => 'porche')); ?>
            <?php echo $form->checkBoxControlGroup($model, 'techo', array('class' => 'porche')); ?>
            <?php echo $form->checkBoxControlGroup($model, 'piso', array('class' => 'porche')); ?>
            <?php echo $form->checkBoxControlGroup($model, 'baranda', array('class' => 'porche')); ?>
            <?php echo $form->checkBoxControlGroup($model, 'cieloraso', array('class' => 'porche')); ?>
            <?php echo $form->checkBoxControlGroup($model, 'estructuraEdificioPrincipal', array('class' => 'porche')); ?>
            <?php echo $form->checkBoxControlGroup($model, 'voladizo', array('class' => 'porche')); ?>
            <?php echo $form->checkBoxControlGroup($model, 'balcones', array('class' => 'porche')); ?>

        </fieldset>
        <fieldset>
            <legend>Garage</legend>
            <?php echo $form->dropDownListControlGroup($model, 'garaje', CHtml::listData(Garage::model()->findAll(), 'id', 'porche'), array('prompt' => Yii::t('App', 'Choose...'))); ?>
            <?php echo $form->textFieldControlGroup($model, 'areaGaraje', array('append' => 'm<sup>2</sup>', 'span' => 8)); ?>
        </fieldset>
        <fieldset>
            <legend>Muro</legend>
            <?php echo $form->dropDownListControlGroup($model, 'materialMuro', CHtml::listData(MaterialMuro::model()->findAll(), 'id', 'materialMuro'), array('prompt' => Yii::t('App', 'Choose...'))); ?>
            <div class="row-fluid">
                <div class="span6"><?php echo $form->dropDownListControlGroup($model, 'altoMuro', array('1' => '1.0m', '1.5' => '1.5m', '2' => '2.0m', '2.5' => '2.5m', '3' => '3.0m', '3.5' => '3.5m', '4' => '4.0m'), array('prompt' => Yii::t('App', 'Choose...'), 'size' => 'medium')); ?></div>
                <div class="span6 "><?php echo $form->textFieldControlGroup($model, 'largoMuro', array('append' => 'm', 'span' => 8)); ?></div>
            </div>


        </fieldset>





    </div>
    <div class="span8">
        <div class="row-fluid">
            <h3 class="span9">Costo Total Catastral Bien Inmueble </h3>
            <h3 class="text-right span3">C$ <span id="ctcbi">0.00</span><?php echo $form->hiddenField($model,'ctcbi'); ?></h3>
        </div>

        <?php echo TbHtml::alert(TbHtml::ALERT_COLOR_INFO, '<strong>TDA</strong> = CTP + CTG + CTM <br /><strong>TDAC</strong> = CCT + TDA <br /> <strong>ADT</strong> = CUT * AreaCatastral'); ?>

        <table class="table table-bordered">
            <tbody>
                <tr>
                    <th class="text-left">Costo Unitario Terreno(CUT)</th>
                    <td><p class="text-right">C$ <span id="cut">0.00</span><?php echo $form->hiddenField($model,'cut'); ?></p></td>
                </tr>
                <tr>
                    <th class="text-left">Vida Problable(VP)</th>
                    <td><p class="text-right"><span id="vp">0</span> años<?php echo $form->hiddenField($model,'vp'); ?></p></td>
                </tr>
                <tr>
                    <th class="text-left">Depreciación Normal(DN)</th>
                    <td><p class="text-right"><span id="dn">0</span>%<?php echo $form->hiddenField($model,'dn'); ?></p></td>
                </tr>
                <tr>
                    <th class="text-left">Total Detalles Adicionales(TDA)</th>
                    <td><p class="text-right">C$ <span id="tda">0.00</span></p><?php echo $form->hiddenField($model,'tda'); ?></td>
                </tr>
                <tr>
                    <th class="text-left">Total Detalles Adicionales y Construcción(TDAC)</th>
                    <td><p class="text-right">C$ <span id="tdac">0.00</span></p><?php echo $form->hiddenField($model,'tdac'); ?></td>
                </tr>
                <tr>
                    <th class="text-left">Costo Despreciado(CD)</th>
                    <td><p class="text-right">C$ <span id="cd">0.00</span></p><?php echo $form->hiddenField($model,'cd'); ?></td>
                </tr>
                <tr>
                    <th class="text-left">Avaluo del Terreno(ADT)</th>
                    <td><p class="text-right">C$ <span id="adt">0.00</span></p><?php echo $form->hiddenField($model,'adt'); ?></td>
                </tr>
            </tbody>
        </table> 

        <div class="row-fluid">
            <h4 class="span9">Costo Construcción Total(CCT) </h4>
            <h3 class="text-right span3">C$ <span id="cct">0.00</span><?php echo $form->hiddenField($model,'cct'); ?></h3>
        </div>

        <?php echo TbHtml::alert(TbHtml::ALERT_COLOR_INFO, '<strong>CCT</strong> = CUB * CBUE'); ?>

        <div class="row-fluid">
            <h4 class="span9">Cálculo del Costo Unitario Básico(CUB) </h4>
            <h3 class="text-right span3">C$ <span id="cub">0.00</span><?php echo $form->hiddenField($model,'cub'); ?></h3>
        </div>

        <?php echo TbHtml::alert(TbHtml::ALERT_COLOR_INFO, '<strong>CUB</strong> = CBUE * FFE * FAE * FNP'); ?>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <th class="text-left">Costo Basico Unitario de Estructura(CBUE)</th>
                    <td><p class="text-right">C$ <span id="cbue">0.00</span></p><?php echo $form->hiddenField($model,'cbue'); ?></td>
                </tr>
                <tr>
                    <th class="text-left">Factor de Forma de la Estructura(FFE)</th>
                    <td><p id="ffe" class="text-right">0.00</p><?php echo $form->hiddenField($model,'ffe'); ?></td>
                </tr>
                <tr>
                    <th class="text-left">Factor de Area de la Estructura(FAE)</th>
                    <td><p id="fae" class="text-right">0.00</p><?php echo $form->hiddenField($model,'fae'); ?></td>
                </tr>
                <tr>
                    <th class="text-left">Factor por Nivel de Planta(FNP)</th>
                    <td><p id="fnp" class="text-right">0.00</p><?php echo $form->hiddenField($model,'fnp'); ?></td>
                </tr>
            </tbody>
        </table>  

        <div class="row-fluid">
            <h4 class="span9">Costo Total Porche(CTP) </h4>
            <h3 class="text-right span3">C$ <span id="ctp">0.00</span><?php echo $form->hiddenField($model,'ctp'); ?></h3>
        </div>

        <?php echo TbHtml::alert(TbHtml::ALERT_COLOR_INFO, '<strong>CTP</strong> = AreaPorche * CUP <br /><strong>CUP</strong> = CBUE * FactorAreaPorche'); ?>

        <table class="table table-bordered">
            <tbody>
                <tr>
                    <th class="text-left">Clase</th>
                    <td><p class="text-right"><span id="clasePorche"></span></p><?php echo $form->hiddenField($model,'clasePorche'); ?></td>
                </tr>
                <tr>
                    <th class="text-left">Factor Area de Porche(FAP)</th>
                    <td><p class="text-right"><span id="fap">0.00</span></p><?php echo $form->hiddenField($model,'fap'); ?></td>
                </tr>
                <tr>
                    <th class="text-left">Costo Unitario Porche(CUP)</th>
                    <td><p class="text-right">C$ <span id="cup">0.00</span></p><?php echo $form->hiddenField($model,'cup'); ?></td>
                </tr>
            </tbody>
        </table>  

        <div class="row-fluid">
            <h4 class="span9">Costo Total Garaje(CTG) </h4>
            <h3 class="text-right span3">C$ <span id="ctg">0.00</span><?php echo $form->hiddenField($model,'ctg'); ?></h3>
        </div>

        <?php echo TbHtml::alert(TbHtml::ALERT_COLOR_INFO, '<strong>CTG</strong> = AreaGaraje * CUG <br /><strong>CUG</strong> = CBUE * FactorAreaGaraje'); ?>

        <table class="table table-bordered">
            <tbody>

                <tr>
                    <th class="text-left">Factor Area de Garaje(FAG)</th>
                    <td><p class="text-right"><span id="fag">0.00</span></p><?php echo $form->hiddenField($model,'fag'); ?></td>
                </tr>
                <tr>
                    <th class="text-left">Costo Unitario Porche(CUG)</th>
                    <td><p class="text-right">C$ <span id="cug">0.00</span></p><?php echo $form->hiddenField($model,'cug'); ?></td>
                </tr>
            </tbody>
        </table>  

        <div class="row-fluid">
            <h4 class="span9">Costo Total Muro(CTM) </h4>
            <h3 class="text-right span3">C$ <span id="ctm">0.00</span><?php echo $form->hiddenField($model,'ctm'); ?></h3>
        </div>

        <?php echo TbHtml::alert(TbHtml::ALERT_COLOR_INFO, '<strong>CTM</strong> = CUM * AltoMuro * LongitudMuro'); ?>

        <table class="table table-bordered">
            <tbody>

                <tr>
                    <th class="text-left">Costo Unitario Muro(CUM)</th>
                    <td><p class="text-right">C$ <span id="cum">0.00</span></p><?php echo $form->hiddenField($model,'cum'); ?></td>
                </tr>

            </tbody>
        </table>  


    </div>
</div>
<div class="form-actions text-right">
    <?php
    echo TbHtml::formActions(array(
        TbHtml::submitButton('Guardar', array('color' => TbHtml::BUTTON_COLOR_PRIMARY, 'size' => TbHtml::BUTTON_SIZE_LARGE)),
        TbHtml::resetButton('Restablecer', array('size' => TbHtml::BUTTON_SIZE_LARGE)),
    ));
    ?>
</div>
<?php $this->endWidget(); ?>
<?php
$cs = Yii::app()->getClientScript();
$cs->registerCssFile(Yii::app()->theme->baseUrl . "/css/bootstrap-combobox.css");
$cs->registerScriptFile(Yii::app()->theme->baseUrl . "/js/bootstrap-combobox.js", CClientScript::POS_END);
$cs->registerScriptFile(Yii::app()->theme->baseUrl . "/js/accounting.js", CClientScript::POS_END);
$cs->registerScript("calculate", '
     $("#CalculadoraForm_barrio").combobox();
     function calculate(){
        var vTotal = 0;
        var vCbue = parseInt($("#cbue").text());
        var vArea = 0;
        var vAreaPorche = 0;
        var vAreaGaraje = 0;
        var vCbu = 0;
        var vCup = 0;
        
        if($("#CalculadoraForm_areaConstruccion").val().trim()!="")
            vArea = parseFloat($("#CalculadoraForm_areaConstruccion").val()).toFixed(2);

        vCbu = vCbue * parseFloat($("#ffe").text()) * parseFloat($("#fae").text()) * parseFloat($("#fnp").text());
        
        vTotal = vCbu * vArea;
        
        //Capturando valores para porche
        if($("#CalculadoraForm_areaPorche").val().trim()!="")
            vAreaPorche = parseFloat($("#CalculadoraForm_areaPorche").val()).toFixed(2);
       
        var vFap = parseFloat($("#fap").text()).toFixed(2);
       
        vCup = vCbue * vFap;
        var vCtp = vCup * vAreaPorche;
        
        //Capturando valores para garaje
        if($("#CalculadoraForm_areaGaraje").val().trim()!="")
            vAreaGaraje = parseFloat($("#CalculadoraForm_areaGaraje").val()).toFixed(2);
       
        var vFag = parseFloat($("#fag").text()).toFixed(2);
       
        var vCug = vCbue * vFag;
        var vCtg = vCup * vAreaGaraje;
        
        //Capturando valores para muro
        var vAltoMuro=0;
        var vLongMuro=0;
        if($("#CalculadoraForm_largoMuro").val().trim()!="")
            vLongMuro = parseFloat($("#CalculadoraForm_largoMuro").val()).toFixed(2);
        if($("#CalculadoraForm_altoMuro").val().trim()!="")
            vAltoMuro = parseFloat($("#CalculadoraForm_altoMuro").val()).toFixed(2);
       
        var vCum = parseFloat($("#cum").text()).toFixed(2);
        var vCtm = vCum * vLongMuro * vAltoMuro;
        
        var vTda = vCtp + vCtg + vCtm;
        var vTdac = vTda + vTotal;
        
        //Capturando valores para terreno
        var vAreaTerreno=0;

        if($("#CalculadoraForm_areaCatastral").val().trim()!="")
            vAreaTerreno = parseFloat($("#CalculadoraForm_areaCatastral").val()).toFixed(2);
       
        var vCut = parseFloat($("#cut").text()).toFixed(2);
        var vAdt = vCut * vAreaTerreno;
        
        var vDn = parseFloat($("#dn").text()/100).toFixed(2);
        var vCd = vDn * vTdac;
        var vbigTotal = vCd + vAdt;
        
        
        $("#cub").html(accounting.formatNumber(vCbu,2,","));
        //Totales de Porche
        $("#cup").html(accounting.formatNumber(vCup,2,","));
        $("#ctp").html(accounting.formatNumber(vCtp,2,","));
        //Totales de Garaje
        $("#cug").html(accounting.formatNumber(vCug,2,","));
        $("#ctg").html(accounting.formatNumber(vCtg,2,","));
        //Totales de Muro
        $("#ctm").html(accounting.formatNumber(vCtm,2,","));
        $("#tda").html(accounting.formatNumber(vTda,2,","));
        $("#tdac").html(accounting.formatNumber(vTdac,2,","));
        $("#cut").html(accounting.formatNumber(vCut,2,","));
        $("#adt").html(accounting.formatNumber(vAdt,2,","));
        $("#cd").html(accounting.formatNumber(vCd,2,","));
        $("#cct").html(accounting.formatNumber(vTotal,2,","));
        $("#ctcbi").html(accounting.formatNumber(vbigTotal,2,","));
        
        //Actualizando los inputs
        $("#CalculadoraForm_ctcbi").val($("#ctcbi").text());
      $("#CalculadoraForm_cut").val($("#cut").text());
      $("#CalculadoraForm_vp").val($("#vp").text());
      $("#CalculadoraForm_dn").val($("#dn").text());
      $("#CalculadoraForm_tda").val($("#tda").text());
      $("#CalculadoraForm_tdac").val($("#tdac").text());
      $("#CalculadoraForm_cd").val($("#cd").text());
      $("#CalculadoraForm_adt").val($("#adt").text());
      $("#CalculadoraForm_cct").val($("#cct").text());
      $("#CalculadoraForm_cub").val($("#cub").text());
      $("#CalculadoraForm_cbue").val($("#cbue").text());
      $("#CalculadoraForm_ffe").val($("#ffe").text());
      $("#CalculadoraForm_fae").val($("#fae").text());
      $("#CalculadoraForm_fnp").val($("#fnp").text());
      $("#CalculadoraForm_ctp").val($("#ctp").text());
      $("#CalculadoraForm_fap").val($("#fap").text());
      $("#CalculadoraForm_cup").val($("#cup").text());
      $("#CalculadoraForm_ctg").val($("#ctg").text());
      $("#CalculadoraForm_fag").val($("#fag").text());
      $("#CalculadoraForm_cug").val($("#cug").text());
      $("#CalculadoraForm_ctm").val($("#ctm").text());
      $("#CalculadoraForm_cum").val($("#cum").text());
      $("#CalculadoraForm_clasePorche").val($("#clasePorche").text());
     }
     $("#CalculadoraForm_clase,#CalculadoraForm_calidad,#CalculadoraForm_areaConstruccion,#CalculadoraForm_edad").change(function(){
        var vCalidad=$("#CalculadoraForm_calidad").val();
        var vClase=$("#CalculadoraForm_clase").val();
        var vArea=$("#CalculadoraForm_areaConstruccion").val();
        
        if(vCalidad !=""){
        
            if(vArea!=""){
                $.ajax({
                    url: "' . Yii::app()->baseUrl . '/index.php/site/factormodificacionxarea",
                    data: { calidad: vCalidad, area: vArea },

                }).done(function (data) {

                    if(data !== null){
                        $("#fae").html(parseFloat(data.factorArea).toFixed(2));
                    }else{
                        $("#fae").html("0.00");
                    }
                    if( console && console.log ) {
                      console.log("FAE:", data);
                    }
                }).complete(function(){
                    calculate();
                }).fail(function() { alert("FAE no cargado"); });
            }
            
            if(vClase !=""){
                $.ajax({
                    url: "' . Yii::app()->baseUrl . '/index.php/site/costounitarioestructura",
                    data: { calidad: vCalidad, claseId: vClase },

                }).done(function (data) {

                    if(data !== null){
                        $("#cbue").html(parseFloat(data.costoUnitario).toFixed(2));
                    }else{
                        $("#cbue").html("0.00");
                    }
                    if( console && console.log ) {
                      console.log("CBUE:", data);
                    }
                }).complete(function(){
                    calculate();
                }).fail(function() { alert("Costo Unitario no cargado"); });
                var vVida=0;
                $.ajax({
                    url: "' . Yii::app()->baseUrl . '/index.php/site/vidaprobable",
                    data: { calidad: vCalidad, claseId: vClase },

                }).done(function (data) {

                    if(data !== null){
                        vVida=parseInt(data.vidaProbable);
                        $("#vp").html(vVida);
                        
                        if($("#CalculadoraForm_edad").val()!=""){
                            var vEdad=$("#CalculadoraForm_edad").val();
                            $.ajax({
                                url: "' . Yii::app()->baseUrl . '/index.php/site/depreciacion",
                                data: { edad: vEdad, vida: vVida },

                            }).done(function (data) {

                                if(data !== null){
                                    $("#dn").html(parseInt(data.pDepreciacion));
                                }else{
                                    $("#dn").html("0");
                                }


                                if( console && console.log ) {
                                  console.log("DN:", data);
                                }
                            }).complete(function(){
                                calculate();
                            }).fail(function() { alert("Depreciacion no cargada"); });
                        }
                    }else{
                        $("#vp").html("0");
                    }
                    
                    
                    if( console && console.log ) {
                      console.log("VP:", data);
                    }
                }).complete(function(){
                    calculate();
                }).fail(function() { alert("Vida probable no cargado"); });
                
                
              }
        }
     });
     
     $("#CalculadoraForm_factorFormaEstructura").change(function(){
        var vId=$(this).val();
            $.ajax({
                url: "' . Yii::app()->baseUrl . '/index.php/site/formaestructura",
                data: { idForma: vId },

            }).done(function (data) {
                
                if(data !== null){
                    $("#ffe").html(parseFloat(data.valorForma).toFixed(2));
                }else{
                    $("#ffe").html("0.00");
                }
                if( console && console.log ) {
                  console.log("FFE:", data);
                }
            }).complete(function(){
                calculate();
            }).fail(function() { alert("Forma estructura no cargado"); });
            
            
     });
     
     $("#CalculadoraForm_factorNivelPlanta").change(function(){
        var vId=$(this).val();
            $.ajax({
                url: "' . Yii::app()->baseUrl . '/index.php/site/nivelplanta",
                data: { idNivel: vId },

            }).done(function (data) {
                
                if(data !== null){
                    $("#fnp").html(parseFloat(data.valorPlanta).toFixed(2));
                }else{
                    $("#fnp").html("0.00");
                }
                if( console && console.log ) {
                  console.log("FNP:", data);
                }
            }).complete(function(){
                calculate();
            }).fail(function() { alert("Forma estructura no cargado"); });
            
            
     });
     
     $(".porche").change(function(){
        var ckPorche = Array();
        $(".porche:checked").each(function(){
            ckPorche.push($(this).attr("id"));
        });


        $.ajax({
            url: "' . Yii::app()->baseUrl . '/index.php/site/porchesbalcones",
            data: { ckporche: ckPorche },

        }).done(function (data) {

            if(data !== null){
                $("#clasePorche").html("P"+data.clase);
                $("#fap").html(parseFloat(data.valor).toFixed(2));
            }else{
                $("#clasePorche").html("");
                $("#fap").html("0.00");
            }
            if( console && console.log ) {
              console.log("Porche:", data);
            }
        }).complete(function(){
            calculate();
        }).fail(function() { alert("Forma estructura no cargado"); });
     });
     

     $("#CalculadoraForm_garaje").change(function(){
            var vId=$(this).val();
            $.ajax({
                url: "' . Yii::app()->baseUrl . '/index.php/site/garage",
                data: { idGarage: vId },

            }).done(function (data) {
                
                if(data !== null){
                    $("#fag").html(parseFloat(data.valor).toFixed(2));
                }else{
                    $("#fag").html("0.00");
                }
                if( console && console.log ) {
                  console.log("FAG:", data);
                }
            }).complete(function(){
                calculate();
            }).fail(function() { alert("Forma estructura no cargado"); });
            
            
     });
     
     //Muros
     $("#CalculadoraForm_altoMuro,#CalculadoraForm_materialMuro,#CalculadoraForm_largoMuro").change(function(){
        var vAlto=$("#CalculadoraForm_altoMuro").val();
        var vMaterial=$("#CalculadoraForm_materialMuro").val();
        
        
        if(vMaterial !=""){
            if(vAlto!=""){
                $.ajax({
                    url: "' . Yii::app()->baseUrl . '/index.php/site/muros",
                    data: { idMaterial: vMaterial, altura: vAlto },

                }).done(function (data) {

                    if(data !== null){
                        $("#cum").html(parseFloat(data.costo).toFixed(2));
                    }else{
                        $("#cum").html("0.00");
                    }
                    if( console && console.log ) {
                      console.log("CUM:", data);
                    }
                }).complete(function(){
                    calculate();
                }).fail(function() { alert("CUM no cargado"); });
            }
       }
     });
     
     $("#CalculadoraForm_barrio").change(function(){
            var vId=$(this).val();
            $.ajax({
                url: "' . Yii::app()->baseUrl . '/index.php/site/datosbarrios",
                data: { idBarrio: vId },

            }).done(function (data) {
                
                if(data !== null){
                    if($("#CalculadoraForm_areaCatastral").val().trim()==""){
                        $("#CalculadoraForm_areaCatastral").val(parseFloat(data.areaTipica).toFixed(2));
                    }
                    $("#CalculadoraForm_numcatastral").val(data.catastral);
                    $("#cut").html(data.cuPavimiento);
                }else{
                    if($("#CalculadoraForm_areaCatastral").val().trim()==""){
                        $("#CalculadoraForm_areaCatastral").val("0.00");
                    }
                    $("#CalculadoraForm_numcatastral").val("");
                    $("#cut").html("0.00");
                }
                if( console && console.log ) {
                  console.log("AC:", data);
                }
            }).complete(function(){
                calculate();
            }).fail(function() { alert("Area de Terreno no cargado"); });
            
            
     });
     
     
     
', CClientScript::POS_READY);
?>

